﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: CompanyInfoDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 未定义
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class CompanyInfoDAL:BaseDAL< CompanyInfo >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< CompanyInfo > SearchCompanyInfo(CompanyInfoQuery queryParam, Pages pages)
        {
            IQueryable< CompanyInfo > iQuery = QueryCompanyInfo(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchCompanyInfoCount(CompanyInfoQuery queryParam)
        {
            return QueryCompanyInfo(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>未定义</returns>
        public IQueryable< CompanyInfo > QueryCompanyInfo(CompanyInfoQuery queryParam)
        {
            IQueryable<CompanyInfo> iQuery = All();
            iQuery = QueryCompanyInfoById(queryParam, iQuery);
            iQuery = QueryCompanyInfoByCompanyCode(queryParam, iQuery);
            iQuery = QueryCompanyInfoByComapnyName(queryParam, iQuery);
            iQuery = QueryCompanyInfoByIsValid(queryParam, iQuery);
            iQuery = QueryCompanyInfoByExpireDate(queryParam, iQuery);
            iQuery = QueryCompanyInfoByMaxEmployee(queryParam, iQuery);
            iQuery = QueryCompanyInfoByCommonEmail(queryParam, iQuery);
            iQuery = QueryCompanyInfoByCommonQQ(queryParam, iQuery);
            iQuery = QueryCompanyInfoByCommonWeiXinNo(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoById(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (queryParam.Id != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByCompanyCode(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CompanyCode))
                iQuery = iQuery.Where(iq => iq.CompanyCode.Contains(queryParam.CompanyCode.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByComapnyName(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ComapnyName))
                iQuery = iQuery.Where(iq => iq.ComapnyName.Contains(queryParam.ComapnyName.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByIsValid(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (queryParam.IsValid != false)
                iQuery = iQuery.Where(iq => iq.IsValid == queryParam.IsValid);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByExpireDate(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (queryParam.ExpireDate != DateTime.MinValue)
                iQuery = iQuery.Where(iq => iq.ExpireDate == queryParam.ExpireDate);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByMaxEmployee(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (queryParam.MaxEmployee != (int)0)
                iQuery = iQuery.Where(iq => iq.MaxEmployee == queryParam.MaxEmployee);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByCommonEmail(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CommonEmail))
                iQuery = iQuery.Where(iq => iq.CommonEmail.Contains(queryParam.CommonEmail.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByCommonQQ(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CommonQQ))
                iQuery = iQuery.Where(iq => iq.CommonQQ.Contains(queryParam.CommonQQ.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CompanyInfo > QueryCompanyInfoByCommonWeiXinNo(CompanyInfoQuery queryParam, IQueryable< CompanyInfo > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CommonWeiXinNo))
                iQuery = iQuery.Where(iq => iq.CommonWeiXinNo.Contains(queryParam.CommonWeiXinNo.Trim()));
            return iQuery;
        }
        #endregion
    }
}    